import {_decorator, Component, Node, Prefab, instantiate} from 'cc';

const {ccclass, property} = _decorator;

@ccclass('EnemiesController')
export class EnemiesController extends Component {
    /**
     * 敌人预制体
     */
    @property(Prefab)
    enemyPrefab: Prefab = null;

    start() {
        // 生成敌人【自动生成（定时器）】
        this.schedule(() => {
            // 从预制体中创建节点
            let enemyNode = instantiate(this.enemyPrefab);
            // 设置父节点
            enemyNode.setParent(this.node.parent);
            // 设置位置
            let dt = Math.floor(Math.random() * 480 + 1);
            enemyNode.setPosition(this.node.position.x + dt, this.node.position.y);
        }, 0.5);
    }

    update(deltaTime: number) {

    }
}

